home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / Depth lib 1.0 folder.sit / Depth lib 1.0 folder / depth_lib 1.0 ƒ / depth 1.0 source & libs / depth.c < prev    next >
Text File  |  1995-12-06  |  3KB  |  122 lines

  1. // depth.c
  2. //
  3. // Library routines for getting and setting the color depth for monitors.
  4. // All of the code originated from Kenneth Worley's Monitor Tricks 1.51 in C++.
  5. // Changed to C by Mark Womack.
  6. //
  7. // 12/07/95    1.0 release
  8. //
  9.  
  10. #include "depth.h"
  11. #include <palettes.h>
  12.  
  13. // MaxScreenDepth returns the maximum bit depth that the monitor is capable of
  14. // (i.e. 8 for 256 colors).
  15. pascal short MaxScreenDepth( GDHandle theGDevice )
  16. {
  17.     short        x;
  18.     short        hasThisDepth=1;
  19.     
  20.     for ( x=2; x<=32; x*=2 )
  21.         if ( HasDepth( theGDevice, x, gdDevType, 1 ) )
  22.             hasThisDepth = x;
  23.         else
  24.             break;
  25.     
  26.     return hasThisDepth;
  27. }
  28.  
  29. // Returns true if the monitor supports the given depth
  30. pascal Boolean SupportsDepth( GDHandle theGDevice, short aDepth)
  31. {
  32.     GDHandle        savedDevice;
  33.     Boolean            val;
  34.     
  35.     savedDevice = GetGDevice();
  36.     SetGDevice( theGDevice );
  37.     
  38.     val = HasDepth( theGDevice, aDepth, 1 << gdDevType, GetScreenMode(theGDevice) );
  39.     
  40.     SetGDevice( savedDevice );
  41.     
  42.     return val;
  43. }
  44.  
  45. // GetScreenDepth returns the current bit depth of this monitor.
  46. pascal short GetScreenDepth( GDHandle theGDevice )
  47. {
  48.     return ((**((**(theGDevice)).gdPMap)).pixelSize);
  49. }
  50.  
  51. // SetScreenDepth changes the bit depth of the screen (the number of colors that it can
  52. // display at once).
  53. pascal void SetScreenDepth( GDHandle theGDevice, short newDepth )
  54. {
  55.     GDHandle        savedDevice;
  56.     
  57.     savedDevice = GetGDevice();
  58.     SetGDevice( theGDevice );
  59.     
  60.     if ( newDepth != GetScreenDepth(theGDevice) )
  61.         if ( HasDepth( theGDevice, newDepth, 1 << gdDevType, GetScreenMode(theGDevice) ) )
  62.             SetDepth( theGDevice, newDepth, 1 << gdDevType, GetScreenMode(theGDevice) );
  63.     
  64.     SetGDevice( savedDevice );
  65. }
  66.  
  67. // Returns true if the monitor supports the given mode
  68. pascal Boolean SupportsMode( GDHandle theGDevice, short aMode)
  69. {
  70.     GDHandle        savedDevice;
  71.     Boolean            val;
  72.     
  73.     savedDevice = GetGDevice();
  74.     SetGDevice( theGDevice );
  75.     
  76.     val =  HasDepth( theGDevice, GetScreenDepth(theGDevice), 1 << gdDevType, aMode );
  77.     
  78.     SetGDevice( savedDevice );
  79.     
  80.     return val;
  81. }
  82.  
  83. // GetScreenMode returns one if the monitor is displaying colors, zero if it's displaying in grays.
  84. pascal short GetScreenMode( GDHandle theGDevice )
  85. {
  86.     if ( TestDeviceAttribute( theGDevice, gdDevType ) )
  87.         return 1;    //colors
  88.     else
  89.         return 0;    //grays
  90. }
  91.  
  92. // SetScreenMode sets this monitor to color if 1 is sent, or grays if zero is sent.
  93. pascal void SetScreenMode( GDHandle theGDevice, short newMode )
  94. {
  95.     GDHandle        savedDevice;
  96.     
  97.     savedDevice = GetGDevice();
  98.     SetGDevice( theGDevice );
  99.     
  100.     if ( newMode != GetScreenMode(theGDevice) )
  101.         if ( HasDepth( theGDevice, GetScreenDepth(theGDevice), 1 << gdDevType, newMode ) )
  102.             SetDepth( theGDevice, GetScreenDepth(theGDevice), 1 << gdDevType, newMode );
  103.     
  104.     SetGDevice( savedDevice );
  105. }
  106.  
  107. // SetScreenModeDepth sets the monitor to the color mode and depth specified.
  108. pascal void SetScreenModeDepth( GDHandle theGDevice, short newDepth, short newMode )
  109. {
  110.     GDHandle        savedDevice;
  111.     
  112.     savedDevice = GetGDevice();
  113.     SetGDevice( theGDevice );
  114.     
  115.     if ( (newDepth != GetScreenDepth(theGDevice)) || (newMode != GetScreenMode(theGDevice)) )
  116.         if ( HasDepth( theGDevice, newDepth, 1 << gdDevType, newMode ) )
  117.             SetDepth( theGDevice, newDepth, 1 << gdDevType, newMode );
  118.     
  119.     SetGDevice( savedDevice );
  120. }
  121.  
  122.